/*
 * @Description:
 * @Author: Cxy
 * @Date: 2024-02-01 15:10:55
 * @LastEditors: Cxy
 * @LastEditTime: 2024-12-22 21:10:40
 * @FilePath: \xy-admin\play\src\api\index.ts
 */
import Axios from './axios'
import type { AxiosResponse } from 'axios'

/* 请求体编码 */
// 'text/html' | 'text/plain' | 'multipart/form-data' | 'application/json'
// 'application/x-www-form-urlencoded' | 'application/octet-stream';

/**
 * @description: get封装
 * @param {string} url
 * @param {any} params
 * @param {AxiosRequestAbortKeyConfig} config
 * @return {Promise<AxiosResponse>}
 */
export const get = (url: string, params?: any, config?: AxiosRequestAbortKeyConfig): Promise<AxiosResponse> => {
  return Axios.get(url, { params, ...config })
}

/**
 * @description: post封装
 * @param {string} url
 * @param {any} data
 * @param {AxiosRequestAbortKeyConfig} config
 * @return {Promise<AxiosResponse>}
 */
export const post = (url: string, data?: any, config?: AxiosRequestAbortKeyConfig): Promise<AxiosResponse> => {
  return Axios.post(url, data, config)
}

/**
 * @description: post 上传 upload封装
 * @param {string} url
 * @param {any} data
 * @param {ProgressFun} progressFun 回调进度
 * @param {AxiosRequestAbortKeyConfig} config
 * @return {Promise<AxiosResponse>}
 */
export const postUpload = (
  url: string,
  data: any,
  progressFun: ProgressFun,
  config?: AxiosRequestAbortKeyConfig
): Promise<AxiosResponse> => {
  return Axios.post(url, data, {
    onUploadProgress(progressEvent) {
      progressFun(progressEvent)
    },
    ...config
  })
}
